

package VISTA;
import MODELO.*;
import CONTROL.*;
/**
 *
 * @author Marco
 */
import javax.swing.table.DefaultTableModel;
public class ExperienciaGUI extends javax.swing.JDialog {
  //para la tabla
 DefaultTableModel modelo;
    
    
    java.util.ArrayList mia;
    java.util.ArrayList mia1;
    java.util.ArrayList mia2;
    int semaforo = 0;
    int semaforo1 = 0;
    int semaforo2 = 0;
    
    public ExperienciaGUI(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        //para la tabla
        TransBDExperiencia.consultarTodos();
        modelo = new DefaultTableModel();
        Object datosTabla []= {"Codigo de usuario" , "Codigo de nivel","Codigo conocimiento","Observacion"};
        modelo.setColumnIdentifiers(datosTabla);
        jTable1.setModel(modelo);
        TransBDExperiencia.Llenalo(modelo);
         //para el primer combox1
         mia = new java.util.ArrayList();
        TransBDUsuario.cargar(jComboBox1, mia);
        System.out.println(mia);
        //para el segundo combox2
         mia1 = new java.util.ArrayList();
        TransBDNivel.cargar(jComboBox2, mia1);
        System.out.println(mia1);
         //para el tercer combox3
         mia2 = new java.util.ArrayList();
        TransBDConocimiento.cargar(jComboBox3, mia2);
        System.out.println(mia2);
        
         TransBDExperiencia.consultarTodos();
        if(ServicioBD.siguiente()){
            Experiencia x=TransBDExperiencia.get();
             muevaloalaventana(x);
        }
        else
            System.out.println("OCURRIO ALGO RARO NO ESPERADO");
    
    }

    
    @SuppressWarnings("unchecked")
    
     public void muevaloalaventana(Experiencia  m){
       jTextField2.setText(m.getObservacion());
       
        jComboBox1.setSelectedItem(m.getUsuCodigo());
        jComboBox2.setSelectedItem(m.getCodnivel());
        jComboBox3.setSelectedItem(m.getCodigocon());
        
        
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/13.png"))); // NOI18N
        jButton6.setText("Adicionar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, 110, 50));

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/44.png"))); // NOI18N
        jButton7.setText("Modificar");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 20, 120, 50));

        jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/Borrar.png"))); // NOI18N
        jButton8.setText("Borrar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 20, 130, 50));

        jButton9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/42.png"))); // NOI18N
        jButton9.setText("Buscar");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 20, 120, 50));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1000, 80));

        jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel2.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setText("Observacion");
        jPanel2.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 110, -1, -1));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/35.png"))); // NOI18N
        jButton1.setText("Regresar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel2.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(647, 535, 130, 40));

        jButton10.setText("...");
        jPanel2.add(jButton10, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 20, -1, -1));

        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 210, 70, -1));

        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 210, 60, -1));

        jComboBox3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox3ActionPerformed(evt);
            }
        });
        jPanel2.add(jComboBox3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 260, 70, -1));
        jPanel2.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 110, 470, -1));
        jPanel2.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 210, 220, -1));
        jPanel2.add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 210, 180, -1));
        jPanel2.add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 260, 220, -1));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jPanel2.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 320, 600, 140));

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 80, 800, 600));

        jPanel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/primeroimag1.jpg"))); // NOI18N
        jButton2.setToolTipText("Primero");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 30, 90, 40));

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/siguiente2.jpg"))); // NOI18N
        jButton3.setToolTipText("Siguiente");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 80, 90, 40));

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/ultimoimag2.jpg"))); // NOI18N
        jButton4.setToolTipText("Ultimo");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 180, 90, 40));

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/IMAGENES/anterior2.jpg"))); // NOI18N
        jButton5.setToolTipText("Anterior");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 130, 90, -1));

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(800, 80, 200, 600));

        jPanel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setText("VENTANA PARA EXPERIENCIA");
        jPanel4.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(12, 13, 166, -1));

        getContentPane().add(jPanel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 680, 1000, 40));

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        // TODO add your handling code here:
       
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        // TODO add your handling code here:
        
        
        
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
// TODO add your handling code here:
     String codigo = jTextField2.getText();
     if (TransBDExperiencia.buscar(codigo)){
         TransBDExperiencia.borrar(codigo);
         System.out.println("ESTO FUNIONA POR AQUI BIEN PORQUE LO ENCONTRO");
     }
     else 
           javax.swing.JOptionPane.showMessageDialog(this, "NO EXISTE PARA BORRARLO");
  
}//GEN-LAST:event_jButton8ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
// TODO add your handling code here:
    String codigo = jTextField2.getText();  
  if (TransBDExperiencia.buscar(codigo)){
       Experiencia x= TransBDExperiencia.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO LO ENCONTRO");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO LO ENCONTRO"); 
      
    
}//GEN-LAST:event_jButton9ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    if (ServicioBD.primero()){
       Experiencia x= TransBDExperiencia.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
   
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here: 
     if (ServicioBD.siguiente()){
       Experiencia x= TransBDExperiencia.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
       muevaloalaventana(x);
}

    
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
    if (ServicioBD.ultimo()){
       Experiencia x= TransBDExperiencia.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
     if (ServicioBD.anterior()){
       Experiencia x= TransBDExperiencia.get();
       if (x!=null)
          muevaloalaventana(x);
       else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
    }
    else
           javax.swing.JOptionPane.showMessageDialog(this, "NO HAY MAS");
}//GEN-LAST:event_jButton5ActionPerformed

private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// TODO add your handling code here:
          if(semaforo==1){
    int n=jComboBox1.getSelectedIndex();
        String NombreUsuario= (String)mia.get(n);
        jTextField3.setText(NombreUsuario);
        

}
    semaforo = 1;
}//GEN-LAST:event_jComboBox1ActionPerformed

private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
// TODO add your handling code here:
     if(semaforo1==1){
    int n=jComboBox2.getSelectedIndex();
        String NombreNivel= (String)mia1.get(n);
        jTextField4.setText(NombreNivel);
        

}
    semaforo1 = 1;
}//GEN-LAST:event_jComboBox2ActionPerformed

private void jComboBox3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox3ActionPerformed
// TODO add your handling code here:
            if(semaforo2==1){
    int n=jComboBox3.getSelectedIndex();
        String Descripcion= (String)mia2.get(n);
        jTextField5.setText(Descripcion);
        

}
    semaforo2 = 1;
}//GEN-LAST:event_jComboBox3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ExperienciaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ExperienciaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ExperienciaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ExperienciaGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                ExperienciaGUI dialog = new ExperienciaGUI(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    // End of variables declaration//GEN-END:variables
}
